package com.bbx.taxi.client.Util;

import java.util.ArrayList;

import android.content.Context;

import com.bbx.api.sdk.model.passanger.Return.MyOrderList.MyOrderList;
import com.bbx.taxi.client.Activity.Menu.MyOrderActivity;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.DB.MyOrder.MyOrderingDB;

/** 
 * @Path com.bbx.taxi.client.Util.IsSnQiangDan.java
 * @Author 严旭文
 * @Date 2016-6-8 上午11:03:38
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 判断是否有市内抢单
 */
public class IsSnQiangDan {
	/**预约跟即时间隔15分钟*/
	public static long Jiange=16;
	/**时间后台的间隔*/
	public static long shijiJiange=15;
	public static long Jiange_time=1000*60*Jiange;
	/**判断是否含有有市内抢单,null就代表没有【即时】
	 * */
    public static String isIncludeSnQiangDan(ArrayList<MyOrderList> list){
    	if(list!=null&&!list.isEmpty()){
    		for(int i=0;i<list.size();i++){
        		int type=list.get(i).getOrder_type();
        		if(type==Value.ORDER_TYPE_SN){
        			int status=list.get(i).getOrder_status();
        			if(isWait(status)&&(DateFormat.onDate_Long(list.get(i).getAppoint_time())-DateFormat.getTime())<=Jiange_time){
        				return list.get(i).getOrder_id();
        			}
        		}
        	}
    	}
		return null;
    }
	/**判断是否含有有市内单,null就代表没有【预约】
	 * */
    public static String isIncludeSnDan(ArrayList<MyOrderList> list){
    	if(list!=null&&!list.isEmpty()){
    		for(int i=0;i<list.size();i++){
        		int type=list.get(i).getOrder_type();
        		if(type==Value.ORDER_TYPE_SN){
        			return list.get(i).getOrder_id();
        		}
        	}
    	}
		return null;
    }
	/**判断是否含有有市内抢单,null就代表没有【即时】
	 * */
    public static String isIncludeSnQiangDanLocal(Context context){
    	MyOrderingDB db_myordering=new MyOrderingDB();
    	ArrayList<MyOrderList> list=db_myordering.onReadDB_ing(MyOrderActivity.num_ing, true);
		return isIncludeSnQiangDan(list);
    }
    /**判断是否有市内单，包含预约【预约】
     * */
    public static String isIncludeSnLocal(Context context){
    	MyOrderingDB db_myordering=new MyOrderingDB();
    	ArrayList<MyOrderList> list=db_myordering.onReadDB_ing(MyOrderActivity.num_ing, true);
		return isIncludeSnDan(list);
    } 
    /**
     * 判断该订单是否是市内抢单
     */
    public static boolean isSnQiangDan(MyOrderList mMyOrderList){
    	try{
    	if(IsSnQiangDan.isWait(mMyOrderList.getOrder_status())&&mMyOrderList.getOrder_type()==Value.ORDER_TYPE_SN
    			&&(DateFormat.onDate_Long(mMyOrderList.getAppoint_time())-DateFormat.getTime())<=Jiange_time){
    		return true;
    	}
    	}catch(Exception e){}
    	return false;
    }
    /**
     * 判断是否是等待派车界面
     */
    public static boolean isWait(int status){
    	if (status == Value.ORDER_STATUS_UNTREATED
				|| status == Value.ORDER_STATUS_TEAM
				|| status == Value.ORDER_STATUS_RETEAM
				|| status == Value.ORDER_STATUS_GAIPAI
				|| status == Value.ORDER_STATUS_KF_GAIPAI) {
    		return true;
    	}
    	return false;
    }
}
